package cn.lianyutiantang.service.user.impl;


import cn.lianyutiantang.dao.FileDao;
import cn.lianyutiantang.model.FileObj;
import cn.lianyutiantang.service.user.FileService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class FileServiceImpl implements FileService {
    @Autowired
    private FileDao fileDao;

    @Transactional(rollbackFor = Throwable.class)
    @Override
    public int create(FileObj entity) {
        return fileDao.create(entity);
    }

    @Override
    public int batchCreate(List<FileObj> list) {
        if (list == null || list.size() == 0) {
            return 0;
        }
        return fileDao.batchCreate(list);
    }

    @Transactional(rollbackFor = Throwable.class)
    @Override
    public int update(FileObj entity) {
        return fileDao.update(entity);
    }

    @Transactional(rollbackFor = Throwable.class)
    @Override
    public int deleteById(String id) {
        return fileDao.deleteById(id);
    }

    @Override
    public FileObj findByMd5(String md5) {
        if (StringUtils.isBlank(md5)) {
            return null;
        }
        return fileDao.findByMd5(md5);
    }

    @Override
    public int updateCallBackReport(FileObj fileObj) {
        return fileDao.updateCallBackReport(fileObj);
    }

    @Override
    public List<FileObj> findByBackAysRemark(String systemBackAysRemark) {
        return fileDao.findByBackAysRemark(systemBackAysRemark);
    }

    @Override
    public int updataBatchSysRemark(List<FileObj> files) {
        if (files == null || files.size() == 0) {
            return 0;
        }
        return fileDao.updataBatchSysRemark(files);
    }

    @Override
    public FileObj getById(String id) {
        return fileDao.getById(id);
    }

    @Override
    public List<FileObj> findByIds(List<String> ids) {
        return fileDao.findByIds(ids);
    }
    @Override
    public List<FileObj> findByYnWorkUploadFileIds(List<String> ids) {
        return fileDao.findByYnWorkUploadFileIds(ids);
    }

    @Override
    public List<FileObj> findByFileList(List<FileObj> list) {
        List<String> ids = new ArrayList<String>();
        for (FileObj fileObj : list) {
            if (StringUtils.isNotBlank(fileObj.getId())) {
                ids.add(fileObj.getId());
            }
        }
        return findByIds(ids);
    }
}